<template>
  <el-container>
    <el-header>
      <el-row>
        <el-col :span="20">
          <el-menu
          :default-active="activeIndex2"
          class="el-menu-demo"
          mode="horizontal"
          @select="handleSelect"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b">
          <el-menu-item index="1">
            主页
          </el-menu-item >
          <el-menu-item index="2">
            库存管理
          </el-menu-item>
        </el-menu>
        </el-col>
        <el-col :span="4" :push="1">
          <el-avatar icon="el-icon-user-solid"></el-avatar>
          <el-button icon="el-icon-remove-outline" @click="logout" type="warning">退出登录</el-button>
        </el-col>
      </el-row>


    </el-header>
      <router-view></router-view>




  </el-container>
</template>

<script>
    export default {
        name: "Home",
      data() {
        return {
          activeIndex: '1',
          activeIndex2: '1'
        };
      },
      methods: {
          // 退出按钮
        logout(){
          this.$http.get("/logout").then(res=>{
            if (res.data.status){
              this.$message({
                message: res.data.message,
                type: 'success'
              });
              this.$router.replace('/')
            }else {
              this.$message.error(res.data.message);
            }

          })
        },
        // 选择菜单路由
        handleSelect(key, keyPath) {
          console.log(key, keyPath);
          if (key==1){
            this.$router.replace('/home/summary')
          }if (key==2){
            this.$router.replace('/home/inventory')
          }
        }
      }
    }
</script>

<style scoped>
  .el-header, .el-footer {
    background-color: #545c64;
    color: #333;
    text-align: center;
    line-height: 60px;
  }

  .el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
    line-height: 200px;
  }

  .el-main {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
    line-height: 160px;
  }

  body > .el-container {
    margin-bottom: 40px;
  }

  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }

  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }
</style>
